Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
change-case
Advanced tools
Convert a string between camelCase, PascalCase, Title Case, snake_case and more.
The change-case package is a utility library that provides various functions to transform strings between different cases, such as camel case, snake case, kebab case, and more. It is useful for formatting strings in different coding conventions or textual formats.
camelCase
Converts a string to camel case.
const { camelCase } = require('change-case');
console.log(camelCase('test string')); // 'testString'
snakeCase
Converts a string to snake case.
const { snakeCase } = require('change-case');
console.log(snakeCase('test string')); // 'test_string'
kebabCase
Converts a string to kebab case.
const { kebabCase } = require('change-case');
console.log(kebabCase('test string')); // 'test-string'
titleCase
Converts a string to title case.
const { titleCase } = require('change-case');
console.log(titleCase('test string')); // 'Test String'
constantCase
Converts a string to constant case.
const { constantCase } = require('change-case');
console.log(constantCase('test string')); // 'TEST_STRING'
Lodash is a comprehensive utility library that includes methods for string case transformation, such as _.camelCase, _.snakeCase, and _.kebabCase. It offers a wider range of utilities beyond string case conversion, making it more versatile but also larger in size compared to change-case.
The 'case' package is another string case conversion library that supports various case transformations. It is similar to change-case but has a different API and may have different case conversion implementations.
String-case is a library that provides case conversion functions similar to change-case. It may offer a different set of features or API design, which could be preferred by some developers over change-case.
Convert strings between camelCase
, PascalCase
, Title Case
, snake_case
, lowercase
, UPPERCASE
, CONSTANT_CASE
and more.
All methods support Unicode (non-ASCII characters) and non-string entities, such as objects with a toString
property, numbers and booleans. Empty values (null
and undefined
) will result in an empty string.
Every method is also available on npm as an individual package.
npm install change-case --save
var changeCase = require('change-case')
//=> { isUpperCase: [Function], camelCase: [Function], ... }
Available methods (short-hand shown below, long-hand available in examples):
isUpper
isLower
upper
ucFirst
lcFirst
lower
sentence
title
camel
pascal
snake
param
dot
path
constant
swap
All methods accept two arguments, the string to change case and an optional locale.
Return a boolean indicating whether the string is upper cased.
changeCase.isUpperCase('test string')
//=> false
Return a boolean indicating whether the string is lower cased.
changeCase.isLowerCase('test string')
//=> true
Return the string in upper case.
changeCase.upperCase('test string')
//=> "TEST STRING"
Return the string with the first character upper cased.
changeCase.upperCaseFirst('test')
//=> "Test"
Return the string with the first character lower cased.
changeCase.lowerCaseFirst('TEST')
//=> "tEST"
Return the string in lower case.
changeCase.lowerCase('TEST STRING')
//=> "test string"
Return as a lower case, space separated string.
changeCase.sentenceCase('testString')
//=> "test string"
Return as a space separated string with the first character of every word upper cased.
changeCase.titleCase('a simple test')
//=> "A Simple Test"
Return as a string with the separators denoted by having the next letter capitalized.
changeCase.camelCase('test string')
//=> "testString"
Return as a string denoted in the same fashion as camelCase
, but with the first letter also capitalized.
changeCase.pascalCase('test string')
//=> "TestString"
Return as a lower case, underscore separated string.
changeCase.snakeCase('test string')
//=> "test_string"
Return as a lower case, dash separated string.
changeCase.paramCase('test string')
//=> "test-string"
Return as a lower case, period separated string.
changeCase.dotCase('test string')
//=> "test.string"
Return as a lower case, slash separated string.
changeCase.pathCase('test string')
//=> "test/string"
Return as an upper case, underscore separated string.
changeCase.constantCase('test string')
//=> "TEST_STRING"
Return as a string with every character case reversed.
changeCase.swapCase('Test String')
//=> "tEST sTRING"
Includes a TypeScript definition.
MIT
FAQs
Transform a string between `camelCase`, `PascalCase`, `Capital Case`, `snake_case`, `kebab-case`, `CONSTANT_CASE` and others
The npm package change-case receives a total of 6,774,441 weekly downloads. As such, change-case popularity was classified as popular.
We found that change-case demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.